package com.sambo.inspection.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.sambo.inspection.InspectionApplication;

public class SpUtil {

    private static final String PREF_NAME = "pref_user";

    private static final Context sContext = InspectionApplication.getInstance();

    // ----------------以下为全局信息缓存-----------------------

    public static String getUserName() {
        SharedPreferences sp = sContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sp.getString("userName", "");
    }

    public static void setUserName(String userName) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit();
        editor.putString("userName", userName).apply();
    }

    public static String getPassword() {
        SharedPreferences sp = sContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sp.getString("password", "");
    }

    public static void setPassword(String password) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit();
        editor.putString("password", password).apply();
    }

    // ----------------以下为用户信息缓存-----------------------

    public static void setUserID(String userName, int id) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE).edit();
        editor.putInt("id", id).apply();
    }

    public static int getUserID(String userName) {
        SharedPreferences sp = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE);
        return sp.getInt("id", 0);
    }

    public static void setPhone(String userName, String phone) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE).edit();
        editor.putString("phone", phone).apply();
    }

    public static String getPhone(String userName) {
        SharedPreferences sp = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE);
        return sp.getString("phone", "");
    }

    public static void setNickName(String userName, String nickName) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE).edit();
        editor.putString("nickName", nickName).apply();
    }

    public static String getNickName(String userName) {
        SharedPreferences sp = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE);
        return sp.getString("nickName", "");
    }

    public static void setMail(String userName, String mail) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE).edit();
        editor.putString("mail", mail).apply();
    }

    public static String getMail(String userName) {
        SharedPreferences sp = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE);
        return sp.getString("mail", "");
    }

    public static void setDeptID(String userName, String deptID) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE).edit();
        editor.putString("deptID", deptID).apply();
    }

    public static String getDeptID(String userName) {
        SharedPreferences sp = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE);
        return sp.getString("deptID", "");
    }

    public static void setLastMessageTS(String userName, long lastMessageTS) {
        SharedPreferences.Editor editor = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE).edit();
        editor.putLong("lastMessageTS", lastMessageTS).apply();
    }

    public static long getLastMessageTS(String userName) {
        SharedPreferences sp = sContext.getSharedPreferences(userName, Context.MODE_PRIVATE);
        return sp.getLong("lastMessageTS", 0);
    }

}
